Lesson 15: 지리정보 시각화

Author

최규빈

Published

July 26, 2023

import numpy as np
import pandas as pd
#---#
import plotly.express as px
import json 
import requests 

데이터 불러오기

global_dict = json.loads(requests.get('https://raw.githubusercontent.com/southkorea/southkorea-maps/master/kostat/2018/json/skorea-provinces-2018-geo.json').text)
local_dict = json.loads(requests.get('https://raw.githubusercontent.com/southkorea/southkorea-maps/master/kostat/2018/json/skorea-municipalities-2018-geo.json').text)
#--#
df = pd.read_csv('https://raw.githubusercontent.com/guebin/PP2024WIN/main/posts/Day3/choro.csv')
df
년도 시도 지역 건물동수 연면적 에너지사용량(TOE)/전기 에너지사용량(TOE)/도시가스 에너지사용량(TOE)/지역난방 code_local code
0 2018 서울특별시 종로구 17929 9141777 64818 82015 111 11010 11
1 2019 서울특별시 종로구 17851 9204140 63492 76653 799 11010 11
2 2020 서울특별시 종로구 17638 9148895 60123 71263 912 11010 11
3 2021 서울특별시 종로구 22845 18551145 125179 117061 0 11010 11
4 2018 서울특별시 중구 10598 10056233 81672 75260 563 11020 11
... ... ... ... ... ... ... ... ... ... ...
995 2021 제주특별자치도 제주시 67053 20275738 103217 25689 0 39010 39
996 2018 제주특별자치도 서귀포시 34154 6914685 34470 1597 0 39020 39
997 2019 제주특별자치도 서귀포시 34729 7233931 34641 1306 0 39020 39
998 2020 제주특별자치도 서귀포시 34880 7330040 35510 1639 0 39020 39
999 2021 제주특별자치도 서귀포시 35230 7512206 37884 2641 0 39020 39

1000 rows × 10 columns

시각화1

fig = px.choropleth_mapbox(
    geojson = global_dict,
    featureidkey = 'properties.code',
    data_frame = df.query('년도 == 2018'),
    locations = 'code',
    color = '에너지사용량(TOE)/전기',
    hover_data = ['시도','지역'],
    #---#
    mapbox_style="carto-positron",
    center={"lat": 36, "lon": 127.5}, 
    zoom=6,
    height=800,
    width=800    
)
fig.show(config={'scrollZoom':False})

시각화2

fig = px.choropleth_mapbox(
    geojson = local_dict,
    featureidkey = 'properties.code',
    data_frame = df.query('년도 == 2018'),
    locations = 'code_local',
    color = '에너지사용량(TOE)/전기',
    hover_data = ['시도','지역'],
    #---#
    mapbox_style="carto-positron",
    center={"lat": 36, "lon": 127.5}, 
    zoom=6,
    height=800,
    width=800    
)
fig.show(config={'scrollZoom':False})